package com.yonyou.cyxdms.sysAuth.service.controller.itemPush;

import org.springframework.web.bind.annotation.*;
import com.yonyou.cyx.framework.controller.base.BaseController;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

import com.yonyou.cyxdms.sysAuth.service.service.itemPush.ItemPushService;
import com.yonyou.cyxdms.sysAuth.service.dto.itemPush.ItemPushDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;


/**
 * @author zhangtan
 * @since 2020-11-19
 */
@RestController
@RequestMapping("/itemPush/itemPush")
public class ItemPushController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(ItemPushController.class);

    @Autowired
    public ItemPushService itemPushService;

    /**
     * 分页查询数据
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author zhangtan
     * @since 2020-11-19
     */
    @ResponseBody
    @GetMapping
    @SuppressWarnings("unchecked")
    public IPage<Map<String, Object>> getList(@RequestParam Map<String, Object> queryCondition, @RequestParam
            ("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        Page<Map<String, Object>> page = new Page(currentPage, pageSize);
        return itemPushService.selectPageBysql(page, queryCondition);
    }

    /**
     * 进行数据修改
     *
     * @param id 数据主键ID
     * @return Map<String,Object> 数据对应的map 结构
     * @author zhangtan
     * @since 2020-11-19
     */
    @ResponseBody
    @GetMapping(value = "/{id}")
    @SuppressWarnings("unchecked")
    public Map<String, Object> getById(@PathVariable("id") Long id) {
        return itemPushService.getById(id);
    }

    /**
     * 进行数据新增
     *
     * @param itemPushDTO 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author zhangtan
     * @since 2020-11-19
     */
    @ResponseBody
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String, Object> insert(@RequestBody ItemPushDTO itemPushDTO) {
        logger.debug("itemPushDTO:{}", itemPushDTO);
        return itemPushService.insert(itemPushDTO);
    }

    /**
     * 进行数据修改
     *
     * @param id          需要修改数据的ID
     * @param itemPushDTO 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author zhangtan
     * @since 2020-11-19
     */
    @ResponseBody
    @PutMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String, Object> update(@PathVariable("id") Long id, @RequestBody ItemPushDTO itemPushDTO) {
        logger.debug("itemPushDTO:{}", itemPushDTO);
        return itemPushService.update(id, itemPushDTO);
    }

    /**
     * 根据id删除对象
     *
     * @param id 需要修改数据的ID
     * @author zhangtan
     * @since 2020-11-19
     */
    @DeleteMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteById(@PathVariable("id") Long id) {
        logger.debug("删除ID:{}", id);
        itemPushService.deleteById(id);
        return true;
    }

    /**
     * 根据IDs批量删除对象
     *
     * @param ids 需要修改数据的ID集合
     * @author zhangtan
     * @since 2020-11-19
     */
    @DeleteMapping(value = "/batch/{ids}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteByIds(@PathVariable("ids") String ids) {
        logger.debug("删除ID:{}", ids);
        itemPushService.deleteBatchIds(ids);
        return true;
    }

    @GetMapping(value = "/pustUserToYUNYANGTask")
    public void pustusertoyunyangtask() {
        itemPushService.pustusertoyunyangtask();
    }
}